﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Synchros
{
    public class SyncIndex
    {
        private int _iIndex = 0;
        private int _iMaxIndex = 0;
        private int _iIndexNumber = 0;

        //得到下一个索引
        public void NextIndex( ref int iSyncTableIndex)
        {
            lock (this)
            {
                if (_iIndex > _iMaxIndex)
                {
                    _iIndex = 0;
                }

                iSyncTableIndex = _iIndex;
                _iIndex++;       
                _iIndexNumber++;         
            }
        }

        //初始化索引起始值
        public void InitIndex(int iRecordCount)
        {
            lock (this)//这里有必要锁吗？
            {
                _iIndex = 0;
                _iMaxIndex = iRecordCount - 1;
                _iIndexNumber = 0;
            }
        }

        //索引编号
        public int IndexNumber
        {
            get { return _iIndexNumber; }
        }
    }
}